<template>
  <div class="copy">
    <span v-if="text" v-clipboard:copy="copyText" v-clipboard:success="onCopy" title="Copy" v-clipboard:error="onError">{{ text }}</span>
    <van-icon v-else :name="iconName" v-clipboard:copy="copyText" v-clipboard:success="onCopy" title="Copy" v-clipboard:error="onError" />
  </div>
</template>
<script>
export default {
  props: {
    iconName: {
      type: String,
      default: 'description'
    },
    copyText: {
      type: String,
      default: ''
    },
    copySuccess: {
      type: Function
    },
    copyError: {
      type: Function
    },
    text: {
      type: String,
      default: ''
    }
  },
  methods: {
    onCopy() {
      if (this.copySuccess) {
        this.copySuccess()
      } else {
        this.$toast(this.$t('info.info12'))
      }
    },
    onError() {
      if (this.copyError) {
        this.copyError()
      } else {
        this.$toast(this.$t('info.info13'))
      }
    }
  }
}
</script>
